import {RuleSelect} from "./RuleSelect";
export class RulePanel{
    private col :any
    private btnSel : any
    public rule: RuleSelect

    constructor(public id:string, private onChoose: (RulePanel)=>void, isCollapse: Boolean = false,public isUse: Boolean = false){
        let m = $(`#${id}`)

        this.col = m.find('.collapse')
        this.collapse(isCollapse)

        let btns = m.find('.btn-group a');
        this.btnSel = btns.first().children()
        btns.first().on('click', ()=>{
            this.isUse = !this.isUse
            this.choose()
        })

        this.rule = new RuleSelect();
    }

    //强制折叠和关闭
    public collapse(isCollapse: Boolean ){
        this.col.collapse(isCollapse ? 'show' : 'hide')
    }

    private choose(){
        if(this.isUse){
            this.btnSel.removeClass("glyphicon-arrow-up")
            this.btnSel.addClass("glyphicon-arrow-down")
        }else{
            this.btnSel.removeClass("glyphicon-arrow-down")
            this.btnSel.addClass("glyphicon-arrow-up")
        }

        this.onChoose(this)
    }
}